
<%@page import="java.util.Vector"%>
<%@page import="javax.swing.JFormattedTextField"%>
<%@page import="javax.swing.text.MaskFormatter"%>
<%@page import="org.xml.sax.Parser"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 import="java.util.ArrayList, db.*"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>

<!-- Icons for Web App<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-icon" sizes="114x114" href="images/nav/index@2x.png">
<link rel="apple-touch-startup-image" href="images/splash/splash-screen.png" media="screen and (max-device-width: 320px)" />
<link rel="apple-touch-startup-image" media="(max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)" href="images/splash/splash-screen@2x.png" />
-->
<title>Frontera Pesos User home</title>
<link href="styles/style.css" rel="stylesheet" type="text/css">
<link href="styles/type.css" rel="stylesheet" type="text/css">
<link href="styles/buttons.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)"	type="text/css" href="styles/highdpi.css" />

<!-- Load the Latest JQuery Version and Latest Validation Plugin -->
<script src="http://code.jquery.com/jquery-latest.js"></script>


<script type="text/javascript">
function checkUserIn(t)
	{
	var selObj = document.getElementById("location");
	var selID = selObj.options[selObj.selectedIndex].id;
	var selText = selObj.options[selObj.selectedIndex].text;
	//alert(selObj.selectedIndex);
	var iMessage = "";
	
	if(selObj.selectedIndex == 0)
		{
		//alert(selID);
		//alert(selText);
			iMessage = iMessage + "Please select a Store!";
		
		}
	 
	if(iMessage != "")
		{
			alert(iMessage);
			iMessage = "";
			return;
		
		}
	document.getElementById("adminRequestType").value = t;
	document.getElementById("userHome").action = "../Admin";
	document.getElementById("userHome").submit();
		
	}
function editPro()
	{
		var UrlLink = "editProfile.jsp";
		window.location.href=UrlLink;
	
	}
function serverPage()
{
	var UrlLink = "server.jsp";
	window.location.href=UrlLink;

}
function adminPage()
{
	var UrlLink = "admin-view.jsp";
	window.location.href=UrlLink;

}

function resetLoc(t)
{ 
document.getElementById("adminRequestType").value = t;
document.getElementById("userHome").action = "../Admin";
document.getElementById("userHome").submit();
	
}
function addReward(coupID,formName,CoupName)
	{
		
		var answer = confirm("I would like to redeem my "+ CoupName + " Coupon");
		var e = document.getElementById(formName);
	if(answer)
			{
			document.getElementById(formName).action = "../Admin";
			e.couponID.value = coupID;
			document.getElementById(formName).submit();
			}
		else
			{
			 return;
			}
	}
</script>
</head>  
<body>

<% DBHelper helper = new DBHelper();
    String serverName =  request.getRemoteHost();
	String _errorMessage = "";
	String _userName = "";
	String _loginID = "";
	String displayRewardsSec = "none";
	int storeCkInId = 0;
	int admin = 0;
	int server = 0;
	int checkID = 0;
	String showAdminBtn = "none";
	String showServerBtn = "none";
	
	Cookie[] cookies = request.getCookies();
	ArrayList<UserData> userInfo =  new ArrayList<UserData>();
	ArrayList<Coupons> couponInfo =  new ArrayList<Coupons>();
	ArrayList<StoreLocation> storeInfo =  new ArrayList<StoreLocation>();
	
	%>

<% 

if(session.getAttribute("userInfo") != null)
	{
		Object t = session.getAttribute("userInfo");
		userInfo = (ArrayList<UserData>) t;
		 for(int i = 0; i < userInfo.size(); i++) {
				System.out.println(" userdata " + userInfo.get(i).getPhoneNumber());
		 }
	} 
if(session.getAttribute("checkinID") != null)
{
	   
	    Object g =  session.getAttribute("checkinID");
	    checkID = Integer.parseInt(g.toString());
	    
}
 if(session.getAttribute("couponInfo") != null)
 {
 	Object t = session.getAttribute("couponInfo");
 	couponInfo = (ArrayList<Coupons>) t;
 	 for(int i = 0; i < couponInfo.size(); i++) {
 			System.out.println(" couponInfo " + couponInfo.get(i).getCouponName());
 	 }
 }	
if(session.getAttribute("storeInfo") != null)
	{
		Object t = session.getAttribute("storeInfo");
		storeInfo = (ArrayList<StoreLocation>) t;
		 for(int i = 0; i < storeInfo.size(); i++) {
				System.out.println(" storeInfo " + storeInfo.get(i).getStoreName());
		 }
	}

if(session.getAttribute("displayRewardsSec") != null)
{
	   
	    Object g =  session.getAttribute("displayRewardsSec");
	    displayRewardsSec = g.toString();
	    
}
if(session.getAttribute("storeCkInId") != null)
{
	   
	    Object g =  session.getAttribute("storeCkInId");
	    storeCkInId = Integer.parseInt(g.toString());
	    
	    System.out.println(" storeCkInId ==  " + storeCkInId);
}

if(session.getAttribute("adminRights") != null)
{
	   
	    Object g =  session.getAttribute("adminRights");
	    admin = Integer.parseInt(g.toString());
	    if(admin == 1)
		{
	    	 showAdminBtn = "inline";
		}
	   
	   
	    System.out.println(" showAdminBtn ==  " + admin);
}
if(session.getAttribute("serverRights") != null)
{
	   
	    Object g =  session.getAttribute("serverRights");
	    server = Integer.parseInt(g.toString());
	    if(server == 1)
		{
	    	showServerBtn = "inline";
		}
	    
	    System.out.println(" showServerBtn ==  " + server);
}


if(session.getAttribute("errorMessage") != null)
  {
    Object g =  session.getAttribute("errorMessage");
    _errorMessage = g.toString();
 }
  else
  {
   _errorMessage = "";
  }
	%>
<%if(session.getAttribute("isCheckedIn") != null)
{ 
		Object g =  session.getAttribute("isCheckedIn");
		int iCk = Integer.parseInt(g.toString());
	
	if(iCk == 1)
	{
		%>	
	<script type="text/javascript">
		alert("You are checked in already!");
	</script>
<%} 
	session.setAttribute("isCheckedIn",0);
} 


%>

	
<div class="landing-page">
	<p class="center-text landing-logo shadow">
	
    	<img src="../assets/FroLogoRetina.png" alt="img" width="125" height="60" class="replace-2x">
        <br/>
  </p>
  
  <div class="login-box">
   <form name="userHome" id="userHome" method="post" action="">
   <span style="display:<%=showAdminBtn%>" id="adminBtn">
   
		<a href="javascript:void(0)" onClick="adminPage()" title="Admin Edit" >
			<img src="../assets/admin.jpg" alt="img" width="50" height="50" class="replace-2x">
		</a>
	</span>&nbsp;&nbsp;&nbsp;
	<span style="display:<%=showServerBtn%>" id="serverBtn" title="Server Detail">
		<a href="javascript:void(0)" onClick="serverPage()" >
		<img src="../assets/waiter3.jpg" alt="img" width="50" height="50" class="replace-2x">
		</a>
	</span>  &nbsp;&nbsp;&nbsp;
	 <span  id="resetcheckIutBtn">
	 	<a href="javascript:void(0)" onClick="resetLoc('resetLoc')" title="Reset Location" >
		<img src="../assets/reset.jpg" alt="img" width="55" height="55" class="replace-2x">
		</a>
		</span>
	<br />
      <br />
     <% for(int i = 0; i < userInfo.size(); i++) { 
    
    %>
     	
     	
     		 <p><%=userInfo.get(i).getUserFullName()%></p>
      		 <p><%=userInfo.get(i).getPhoneNumber()%></p>
		      <p><%=userInfo.get(i).getUserEmail()%></p>
		      <p>My Pesos Balance: <%=userInfo.get(i).getTotalPesos()%> </p>
		      <p><a href="javascript:void(0)" onclick="editPro()">Edit Profile</a></p>
		      <p>&nbsp;</p>
		      <p>&nbsp;</p>
	<%} %>
     
        <p>
          <select name="location" id="location">
          <option>Select Location</option>
           <% for(int i = 0; i < storeInfo.size(); i++) { 
     				System.out.println(" userdata  "+ i);%>
            
            <option <%if(storeCkInId == storeInfo.get(i).getStoreTableID()){ %> selected <%} %> value="<%=storeInfo.get(i).getStoreTableID()%>"><%=storeInfo.get(i).getStoreName()%></option>
           <%} %>
        </select>
         <input type="hidden" name="adminRequestType" id="adminRequestType" value="checkIn" placeholder="adminRequestType" />
       
		 
        <span class="buttonBig"><a href="javascript:void(0)" onClick="checkUserIn('checkIn')" class="buttonBigBlue">Check In</a></span></p>
       
      </form>
      <br>
      <span id="rewards" style="display:<%=displayRewardsSec%>;">
      
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <h2>&nbsp;</h2>
      <h2>Specials</h2>
      <p>&nbsp;</p>
      <form name="specicals" id="specials" method="post" action="">
      <input type="hidden" name="adminRequestType" id="adminRequestType" value="Redeem" placeholder="adminRequestType" />
      <input type="hidden" name="couponID" id="couponID" value="" placeholder="adminRequestType" />
    	 <% for(int i = 0; i < couponInfo.size(); i++) { 
     System.out.println(" coupons kd l "+ i);%>
     <div class="customer-box">
        <a href="javascript:void(0)" onclick="addReward(<%=couponInfo.get(i).getCouponId() %>,'specials','<%=couponInfo.get(i).getCouponName()%>')" >
	    	<p><%=couponInfo.get(i).getCouponName()%></p>
	    </a>
       </div>   
      
       <%} %>
      </form>
      <p>&nbsp;</p>
      <h2>&nbsp;</h2>
      <h2>Redeem</h2>
      <p>&nbsp;</p>
      <form name="Redeem" id="Redeem" method="post" action="">
    <input type="hidden" name="adminRequestType" id="adminRequestType" value="Redeem" placeholder="adminRequestType" />
    <input type="hidden" name="couponID" id="couponID" value="" placeholder="adminRequestType" />
       <% for(int i = 0; i < couponInfo.size(); i++) { 
     System.out.println(" Redeem  "+ couponInfo.get(i).getPointValue());
     if(userInfo.get(0).getTotalPesos() > couponInfo.get(i).getPointValue())
     {%>
     
    	 <div class="customer-box">
         <a href="javascript:void(0)" onclick="addReward(<%=couponInfo.get(i).getCouponId() %>,'Redeem','<%=couponInfo.get(i).getCouponName()%>')" >
	    	<p><%=couponInfo.get(i).getCouponName()%></p>
        	<p><%=couponInfo.get(i).getPointValue()%> Pesos</p>
        </a>
       </div>
    <%} %>
   <%} %>
     </form>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <h2>&nbsp;</h2>
      <h2>Almost There!</h2>
      <p>&nbsp;</p>
      <form name="AlmostThere" id="AlmostThere" method="post" action="">
     <input type="hidden" name="adminRequestType" id="adminRequestType" value="Redeem" placeholder="adminRequestType" />
     <input type="hidden" name="couponID" id="couponID" value="" placeholder="adminRequestType" />
    
       <% for(int p = 0; p < couponInfo.size(); p++) { 
     System.out.println(" Almost There "+ p);
     if(userInfo.get(0).getTotalPesos() < couponInfo.get(p).getPointValue())
     {%>
    	 <div class="customer-box">
         <a href="javascript:void(0)" onclick="addReward(<%=couponInfo.get(p).getCouponId() %>,'AlmostThere','<%=couponInfo.get(p).getCouponName()%>')" >
	    	<p><%=couponInfo.get(p).getCouponName()%></p>
         	<p><%=couponInfo.get(p).getPointValue()%> Pesos</p>
         </a>
       </div>
    <%} %>
   <%} %>
     </form>
     </span>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <div class="clear"></div>
   </div>
    <div class="login-box-deco1"></div>
    <div class="login-box-deco2"></div>

<!--	<p class="login-note shadow"><strong>*</strong>Forgot my Password</p> -->
<div style="height:25px;"></div>
  
 
 
</div>
<%
session.setAttribute("errorMessage","");
%>
</body>
</html>